Skip to content

CLI for testing - #44

Merged
kroekle merged 7 commits into
mainfrom
cli
Jun 12, 2026
Merged

CLI for testing#44
kroekle merged 7 commits into
mainfrom
cli

Conversation

@kroekle

@kroekle kroekle commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Adds a new :cli Gradle module (regoj) — a small command-line driver for the SDK intended for local testing and benchmarking only. It is explicitly excluded from Maven Central publication and the README carries a prominent warning directing users to the official OPA CLI for production workflows.

Why

We need a quick way to load plan bundles, evaluate entrypoints, and inspect metrics/traces/profiles/coverage when developing and benchmarking the SDK, without standing up a full host application each time.

What's included

  • New cli module wired into the multi-module build, using picocli for arg parsing and commons-compress for tarball bundles.
  • eval subcommand supporting:
    • .tar.gz/.tgz plan bundles or unpacked directories (repeatable -b)
    • input from file (-i) or stdin (-I)
    • json / pretty output
    • --metrics / --instrument, --profile (with --profile-limit, --profile-sort), --coverage, --explain
    • --fail / --fail-defined for shell exit-code gating
    • --count for repeated runs with min/max/mean/p90/p99 reporting; --count-includes-load to include bundle load/engine build per iteration
    • --capabilities-current to dump registered builtin capabilities
  • print() output forwarded to stderr.
  • Build script skips the com.vanniktech.maven.publish configuration for :cli so it is not published.
  • Module README documents usage, flags, and examples, with a clear "testing/benchmarking only" warning.
  • .gitignore updates for .out/.

Signed-off-by: Kurt Roekle <k_roekle@apple.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new Gradle :cli module (regoj) that provides a local-only command-line driver for the Java OPA SDK, intended for developer testing and benchmarking (and explicitly excluded from Maven Central publication).

Changes:

  • Adds :cli module wiring, build config, and a README documenting local/testing-only usage.
  • Implements an eval subcommand (picocli) that loads plan bundles (dir or .tar.gz), evaluates an entrypoint, and can emit metrics/trace/profile/coverage output.
  • Adds JUnit tests + bundled test resources to validate core CLI behavior and outputs; updates .gitignore for .out/.

Reviewed changes

Copilot reviewed 17 out of 19 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
settings.gradle.kts Includes the new cli module in the multi-module build.
build.gradle.kts Skips Maven publish plugin/config for :cli to avoid publishing.
.gitignore Ignores .out/ artifacts.
cli/build.gradle.kts Adds application module build config + dependencies + run task settings.
cli/README.md Documents regoj usage, flags, and local-only warning.
cli/src/main/java/io/github/open_policy_agent/opa/cli/Regoj.java CLI entrypoint wiring for picocli.
cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Implements eval command: bundle load, evaluation loop, output + reporting.
cli/src/main/java/io/github/open_policy_agent/opa/cli/Format.java Shared formatting helpers (durations, file references).
cli/src/main/java/io/github/open_policy_agent/opa/cli/MetricsReporter.java Renders single-run vs statistical metrics tables.
cli/src/main/java/io/github/open_policy_agent/opa/cli/TraceReporter.java Renders statement enter/exit trace output.
cli/src/main/java/io/github/open_policy_agent/opa/cli/ProfileReporter.java Renders per-location profiling tables (single/statistical).
cli/src/main/java/io/github/open_policy_agent/opa/cli/StatementReporter.java Renders per-statement profiling tables (single/statistical).
cli/src/main/java/io/github/open_policy_agent/opa/cli/CoverageReporter.java Renders per-file covered-line ranges.
cli/src/test/java/io/github/open_policy_agent/opa/cli/CliTest.java End-to-end-ish tests for CLI flags, output formats, and reports.
cli/src/test/resources/input.json Test input document.
cli/src/test/resources/ir_simple_dir/.manifest Bundle manifest for test plan directory.
cli/src/test/resources/ir_simple_dir/data.json Bundle data for tests.
cli/src/test/resources/ir_simple_dir/plan.json Compiled plan bundle used by tests.
cli/src/test/resources/ir_simple_dir/simple.rego Source rego file referenced by the plan and used for coverage/trace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Comment thread cli/build.gradle.kts
Comment thread cli/README.md
Comment thread cli/README.md Outdated
Signed-off-by: Kurt Roekle <k_roekle@apple.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 19 changed files in this pull request and generated 4 comments.

Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Outdated
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Signed-off-by: Kurt Roekle <k_roekle@apple.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 19 changed files in this pull request and generated 5 comments.

Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Regoj.java
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Outdated
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Outdated
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Outdated
Signed-off-by: Kurt Roekle <k_roekle@apple.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 19 changed files in this pull request and generated 6 comments.

Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Outdated
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Outdated
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Outdated
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java Outdated
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Signed-off-by: Kurt Roekle <k_roekle@apple.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 19 changed files in this pull request and generated 1 comment.

Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Signed-off-by: Kurt Roekle <k_roekle@apple.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 19 changed files in this pull request and generated 3 comments.

Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Eval.java
Comment thread cli/build.gradle.kts
Comment thread cli/src/main/java/io/github/open_policy_agent/opa/cli/Format.java
Signed-off-by: Kurt Roekle <k_roekle@apple.com>
@kroekle
kroekle requested review from johanfylling and sspaink June 9, 2026 19:01

@sspaink sspaink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, tried it out locally and works as the readme describes 👍

@kroekle
kroekle merged commit 69aba95 into main Jun 12, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants